import Vue from 'vue'

export default function () {
    Vue.directive('shortcut', {
        inserted: (el, binding) => {
            for (let i = 0; i < el.childNodes.length; i++) {
                if (el.childNodes[i].tagName === 'SPAN') {
                    el.childNodes[i].innerHTML = binding.value + ':' + el.childNodes[i].innerHTML
                    break
                }
            }
            document.addEventListener('keydown', (e) => {
                if (e.key === binding.value) {
                    e.preventDefault()
                    e.stopPropagation()
                    el.click()
                }

            })
        },
    })
}
